using System;
using UnityEngine;

namespace MaterialUI
{
	public abstract class DialogAnimator
	{
		protected MaterialDialog m_Dialog;

		protected float m_AnimationDuration;

		private CanvasGroup m_Background;

		private float m_BackgroundAlpha = 0.5f;

		public MaterialDialog dialog
		{
			get
			{
				return m_Dialog;
			}
			set
			{
				m_Dialog = value;
			}
		}

		public float animationDuration => m_AnimationDuration;

		public CanvasGroup background
		{
			get
			{
				if (m_Background == null)
				{
					m_Background = PrefabManager.InstantiateGameObject("Dialogs/Dialog Background", m_Dialog.rectTransform.parent).GetComponent<CanvasGroup>();
					RectTransform rectTransform = m_Background.transform as RectTransform;
					rectTransform.SetAsFirstSibling();
					rectTransform.anchoredPosition = Vector2.zero;
					rectTransform.sizeDelta = Vector2.zero;
					m_Background.GetComponent<DialogBackground>().dialogAnimator = this;
				}
				return m_Background;
			}
		}

		public float backgroundAlpha
		{
			get
			{
				return m_BackgroundAlpha;
			}
			set
			{
				m_BackgroundAlpha = value;
			}
		}

		public DialogAnimator(float animationDuration = 0.5f)
		{
			m_AnimationDuration = animationDuration;
		}

		public virtual void AnimateShow(Action callback)
		{
			AnimateShowBackground();
		}

		public virtual void AnimateShowBackground()
		{
			background.blocksRaycasts = true;
			TweenManager.TweenFloat(delegate(float f)
			{
				background.alpha = f;
			}, background.alpha, m_BackgroundAlpha, m_AnimationDuration);
		}

		public virtual void AnimateHide(Action callback)
		{
			AnimateHideBackground();
		}

		public virtual void AnimateHideBackground()
		{
			background.blocksRaycasts = false;
			TweenManager.TweenFloat(delegate(float f)
			{
				background.alpha = f;
			}, background.alpha, 0f, m_AnimationDuration, 0f, delegate
			{
				UnityEngine.Object.Destroy(background.gameObject);
			}, scaledTime: false, Tween.TweenType.Linear);
		}

		public virtual void OnBackgroundClick()
		{
			m_Dialog.OnBackgroundClick();
		}
	}
}
